package com.dragon.modules.yuegou.client.wechat_mini.client.impl;

import com.dragon.modules.yuegou.client.wechat_mini.client.LiveClient;
import com.dragon.modules.yuegou.client.wechat_mini.common.BaseResponse;
import com.dragon.modules.yuegou.client.wechat_mini.conn.IMiniClient;
import com.dragon.modules.yuegou.client.wechat_mini.request.GetGoodsWareHouseRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GetLiveInfoRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GetReplayRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GoodsAddRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GoodsAuditRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GoodsDeleteRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GoodsResetAuditRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.GoodsUpdateRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.RoomAddgoodsRequest;
import com.dragon.modules.yuegou.client.wechat_mini.request.RoomCreateRequest;
import com.dragon.modules.yuegou.client.wechat_mini.response.GetGoodsWareHouseResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.GetLiveInfoResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.GetReplayResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.GoodsAddResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.GoodsGetApprovedResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.MediaUploadResponse;
import com.dragon.modules.yuegou.client.wechat_mini.response.RoomCreateResponse;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

public class LiveClientImpl implements LiveClient {

	private final IMiniClient client;

	public LiveClientImpl(IMiniClient client) {
		this.client = client;
	}

	@Override
	public MediaUploadResponse mediaUpload(String accessToken, String type, File file) {
		if (StringUtils.isEmpty(type)) {
			type = "image";
		}
		return client.post("/cgi-bin/media/upload").accessToken(accessToken).parameter("type", type).media(file)
				.execute(MediaUploadResponse.class);
	}

	@Override
	public RoomCreateResponse roomCreate(String accessToken, RoomCreateRequest request) {
		return client.post("/wxaapi/broadcast/room/create").accessToken(accessToken).json(request)
				.execute(RoomCreateResponse.class);
	}

	@Override
	public GetLiveInfoResponse getLiveInfo(String accessToken, GetLiveInfoRequest request) {
		return client.post("/wxa/business/getliveinfo").accessToken(accessToken).json(request)
				.execute(GetLiveInfoResponse.class);
	}

	@Override
	public GetReplayResponse getReplay(String accessToken, GetReplayRequest request) {
		return client.post("/wxa/business/getliveinfo").accessToken(accessToken).json(request)
				.execute(GetReplayResponse.class);
	}

	@Override
	public BaseResponse roomAddgoods(String accessToken, RoomAddgoodsRequest request) {
		return client.post("/wxaapi/broadcast/room/addgoods").accessToken(accessToken).json(request)
				.execute(BaseResponse.class);
	}

	@Override
	public GoodsAddResponse goodsAdd(String accessToken, GoodsAddRequest request) {
		return client.post("/wxaapi/broadcast/goods/add").accessToken(accessToken).json(request)
				.execute(GoodsAddResponse.class);
	}

	@Override
	public BaseResponse goodsResetAudit(String accessToken, GoodsResetAuditRequest request) {
		return client.post("/wxaapi/broadcast/goods/resetaudit").accessToken(accessToken).json(request)
				.execute(BaseResponse.class);
	}

	@Override
	public BaseResponse goodsAudit(String accessToken, GoodsAuditRequest request) {
		return client.post("/wxaapi/broadcast/goods/audit").accessToken(accessToken).json(request)
				.execute(BaseResponse.class);
	}

	@Override
	public BaseResponse goodsDelete(String accessToken, GoodsDeleteRequest request) {
		return client.post("/wxaapi/broadcast/goods/delete").accessToken(accessToken).json(request)
				.execute(BaseResponse.class);
	}

	@Override
	public BaseResponse goodsUpdate(String accessToken, GoodsUpdateRequest request) {
		return client.post("/wxaapi/broadcast/goods/update").accessToken(accessToken).json(request)
				.execute(BaseResponse.class);
	}

	@Override
	public GetGoodsWareHouseResponse getGoodsWareHouse(String accessToken, GetGoodsWareHouseRequest request) {
		return client.post("/wxa/business/getgoodswarehouse").accessToken(accessToken).json(request)
				.execute(GetGoodsWareHouseResponse.class);
	}

	@Override
	public GoodsGetApprovedResponse goodsGetApproved(String accessToken, Integer offset, Integer limit,
			Integer status) {
		return client.get("/wxaapi/broadcast/goods/getapproved").accessToken(accessToken)
				.parameter("offset", offset.toString()).parameter("limit", limit.toString())
				.parameter("status", status.toString()).execute(GoodsGetApprovedResponse.class);
	}

}
